package com.codinghero.example.jdk.lock.waitnotify;

import java.util.concurrent.TimeUnit;

/**
 * the wait & notify usage example
 * 
 * @author liutong
 * 
 */
public class WaitNotifyExample {

	static Object SYNC = new Object();

	public static void main(String[] args) {
		try {
			Thread t1 = new Thread(new PrintThread());
			t1.start();
			Thread t2 = new Thread(new PrintThread());
			t2.start();
			TimeUnit.MILLISECONDS.sleep(5000);
			synchronized (SYNC) {
				SYNC.notifyAll();
				System.out.println("notify");
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			System.out.println("end");
		}
	}
}
